package com.share.commons.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateFormatUtil {
	
	public static final String FORMAT_STYLE_A = "yyyy-MM" ;
	public static final String FORMAT_STYLE_B = "MM-dd" ;
	public static final String FORMAT_STYLE_C = "HH:mm" ;
	public static final String FORMAT_STYLE_D = "MM-dd HH:mm" ;
	public static final String FORMAT_STYLE_E = "yyyy-MM-dd HH:mm" ;
	public static final String FORMAT_STYLE_F = "yyyy-MM-dd HH:mm:ss" ;
	public static final String FORMAT_STYLE_G = "yyyy-MM-dd" ;

	/** 年-月 */
	public static String formatA(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_A) ;
		return sdf.format(date) ;
	}
	/** 月-日 */
	public static String formatB(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_B) ;
		return sdf.format(date) ;
	}
	/** 时-分 */
	public static String formatC(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_C) ;
		return sdf.format(date) ;
	}
	/** 月-日 时:分 */
	public static String formatD(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_D) ;
		return sdf.format(date) ;
	}
	/** 年-月-日 时:分 */
	public static String formatE(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_E) ;
		return sdf.format(date) ;
	}
	/** 年-月-日 时:分:秒 */
	public static String formatF(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_F) ;
		return sdf.format(date) ;
	}
	
	/**
	 * 获得上、下午
	 * @return
	 */
	public static String getAP_PM() {
		int am_pm = Calendar.getInstance().get(Calendar.AM_PM);
		switch (am_pm) {
		case 0:
			return "上午";
		case 1:
			return "下午";
		}
		return "获得AM_PM失败" ;
	}
	
	/**
	 * 获得当前日期的周几
	 * @return
	 */
	public static String getWeek() {
		return convertWeek(Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1) ;
	}
	
	/**
	 * 获得指定日期的周几
	 * @param date java.util.Date日期对象
	 * @return
	 */
	public static String getWeek(Date date) {
		Calendar calendar = Calendar.getInstance(); 
		calendar.setTime(date) ;
		return convertWeek(Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1) ;
	}
	
	/**
	 * 获得指定日期的周几
	 * @param date 字符串
	 * @return
	 */
	public static String getWeek(String date) {
		Calendar calendar = Calendar.getInstance(); 
		try {
			calendar.setTime(new SimpleDateFormat(FORMAT_STYLE_G).parse(date)) ;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return convertWeek(calendar.get(Calendar.DAY_OF_WEEK) - 1) ;
	}

	/**
	 * 获得周几
	 * @return
	 */
	public static String convertWeek(int week) {
		
		switch (week) {
		case 0:
			return "星期日";
		case 1:
			return "星期一";
		case 2:
			return "星期二";
		case 3:
			return "星期三";
		case 4:
			return "星期四";
		case 5:
			return "星期五";
		case 6:
			return "星期六";
		}
		return "日前操作失败";
	}
	
	public static void main(String[] args) {
		System.out.println(getWeek("2010-10-6"));
	}
	
}
